app.controller('ShiftListCtrl', function ($scope, ajax, toaster) {

	$scope.reload = $scope.page.loader('shift/bk/{pageIndex}/{pageSize}/page');
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p, $scope.queryMap); });
	$scope.reload(1);

	//模糊查询
	$scope.queryMap = {};
	$scope.timeRange = {};
	$scope.query = function () {
		if ($scope.timeRange.startTime && $scope.timeRange.endTime) {
			var starTime = $scope.timeRange.startTime.pattern("yyyy-MM-dd");
			var endTime = $scope.timeRange.endTime.pattern("yyyy-MM-dd");
			$scope.queryMap.departureDate = starTime + "#@" + endTime;
		} else if ($scope.timeRange.startTime == null || $scope.timeRange.endTime == null) {
			delete $scope.queryMap.departureDate;
		}
		$scope.reload(1, $scope.queryMap);
	};

	//同步站点
	$scope.sync = function () {
		var url = 'shift/bk/sync';
		ajax.call(new Req.POST({ resource: url })).then(function (result) {
			if (result.code == 200) {
				toaster.pop('success', '成功', '同步信息成功。');
				$scope.reload(1);
			} else {
				toaster.pop('error', '错误', '同步信息失败！');
			}
		}, function () {
			toaster.pop('error', '错误', '同步信息失败！');
		});
	};
});
